#define _CRT_SECURE_NO_WARNINGS 1

/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     struct TreeNode *left;
 *     struct TreeNode *right;
 * };
 */
bool Sum(struct TreeNode* node, int sm, int targetSum)
{
    if (node == NULL)
    {
        return false;
    }
    if (node->left == NULL && node->left == node->right)
    {
        if (node->val + sm == targetSum)
        {
            return true;
        }
        return false;
    }
    bool le = Sum(node->left, sm + node->val, targetSum);
    bool ri = Sum(node->right, sm + node->val, targetSum);

    return le || ri;
}
bool hasPathSum(struct TreeNode* root, int targetSum) {
    return Sum(root, 0, targetSum);
}